<template>
	<div>
		<!-- 自定义头部 -->
		<u-navbar title="库存预警">
			<div slot="right">
				<!-- #ifndef MP-WEIXIN -->
				<div class="btn" @click="update">完成</div>
				<!-- #endif -->
			</div>
		</u-navbar>
		<div class="name padding-0-32" :class="{'m-top':deviceType == 'pad'}">
			<u-input height="94" :focus="true" maxlength="16" v-model="stockWarning" placeholder="" type="number"
				:border="false" />
		</div>
	<!-- #ifdef MP-WEIXIN -->
	<div class="btn-a" @click="update">完成</div>
		<!-- #endif -->
	</div>
</template>

<script>
	import {
		updateStockWarning
	} from "@/api/shops";
	const systemInfo = uni.getSystemInfoSync()
	export default {
		data() {
			return {
				stockWarning: 0, // 库存预警数量
				ktxWindowWidth: systemInfo.windowWidth,
				deviceType:''
			};
		},
		onLoad(options) {
			this.stockWarning = options.num;
			// console.log(uni.getSystemInfo.device)
			// console.log('ss')
			uni.getSystemInfo({
				success: (res) => {
					this.deviceType = res.deviceType
				}
			})
		},
		methods: {
			isPositiveInteger(str) {
			// 判断字符串是否为大于等于0的正整数
			var reg = /^[1-9]\d*|0$/;
			return reg.test(str);
			},
			async update() {
				let isOk=this.isPositiveInteger(this.stockWarning)
				if(!isOk){
					uni.showToast({
					title:"预警数量必须大于等于0",
					icon:"none"
					})
					return
				}
				let res = await updateStockWarning({
					stockWarning: this.stockWarning
				});
				if (res.data.success) {
					uni.navigateBack();
				}
			},
			
		},
	};
</script>

<style lang="scss" scoped>
	.name {

		background: #f3f5f7;
		margin-bottom: 32rpx;
		margin:50rpx 32rpx;
	}
.m-top {
			margin-top: 20rpx;
		}
	.padding-0-32 {
		padding: 0 32rpx;
	}

	.btn {
		display: inline;
		padding: 12rpx 32rpx;
		background: #333;
		border-radius: 10rpx;
		font-size: 24rpx;
		color: #fff;
		margin-right: 24rpx;
	}
	.btn-a {
		padding: 12rpx 32rpx;
		background: #333;
		border-radius: 10rpx;
		font-size: 24rpx;
		color: #fff;
		margin-right: 24rpx;
		margin:50rpx 32rpx;
		text-align: center;
	}

	@media screen and(min-width:750rpx) {
		/deep/ .u-navbar-inner {
			height: 100rpx !important;
		}

		/deep/ .u-navbar-placeholder {
			height: 100rpx !important;
		}
	}

</style>
